package indv.cfeng.fianceCampus.serviceCore.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @author Cfeng
 * @date 2022/10/15
 * mybatis-plus配置类，这里主要是配置mybatis自带的分页插件，之前mybatis时使用的pageHelper
 */

@Configuration
@MapperScan("indv.cfeng.fianceCampus.serviceCore.mapper")
@EnableTransactionManagement //开启事务
public class MybatisPlusConfig {

    /**
     * 添加mybatis-plus分页插件
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        //添加分页插件
        PaginationInnerInterceptor paginationUtil = new PaginationInnerInterceptor();
        //设置请求的页面大于最大页后操作，false --- 继续请求
        paginationUtil.setOverflow(false);
        //单页数目最大限制，默认无
        paginationUtil.setMaxLimit(500L);
        //数据库类型
        paginationUtil.setDbType(DbType.MYSQL);
        interceptor.addInnerInterceptor(paginationUtil);

        return interceptor;
    }
}
